package com.clive.ttweb.controller;

import com.clive.ttweb.bean.Dishes;
import com.clive.ttweb.service.DishesService;
import com.clive.ttweb.vo.DishResult;
import com.clive.ttweb.vo.DishesVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RequestMapping("/dish")
@CrossOrigin
@RestController
public class DishController {
    @Autowired
    private DishesService dishesService;
    @RequestMapping("/addDishes")
    public DishResult addDishes(@RequestBody @Valid Dishes dishes){
        int i = dishesService.addDishes(dishes);
        return DishResult.ok().data("i",i);
    }
    @RequestMapping("/queryDish/{currentPage}/{limit}")
    public DishResult queryDish(@RequestBody Dishes dishes,@PathVariable Integer currentPage,@PathVariable Integer limit){
        DishesVo vo = dishesService.queryDish(currentPage,limit,dishes);
        return DishResult.ok().data("dishList",vo);
    }
    @RequestMapping("/deleteDish/{id}")
    public DishResult deleteDish(@PathVariable Integer id){
        int i = dishesService.deleteDishById(id);
        return DishResult.ok().data("i",i);
    }
    @RequestMapping("/findDishOne/{id}")
    public DishResult findDishOne(@PathVariable Integer id){
        Dishes dishes = dishesService.findDishOne(id);
        return DishResult.ok().data("dishes",dishes);
    }
    @RequestMapping("/updateDish")
    public DishResult updateDish(@RequestBody @Valid Dishes dishes){
        int i = dishesService.updateDish(dishes);
        return DishResult.ok().data("i",i);
    }
}
